/*
 * User Module
 * 用户的管理
 */

Ext.define('MyDesktop.view.UserModule', {
    extend: 'Ext.ux.desktop.Module',

    requires: [
               'Ext.grid.*',
               'Ext.data.*',
               'Ext.util.*',
               'Ext.state.*',
               'Ext.form.*'
    ],

    id:'user-manage',

    init : function(){
        this.launcher = {
            text: 'User Manage',
            iconCls:'icon-grid'
        };
    },

    createWindow : function(){
    	var me = this;
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('user-manage');
        var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
            clicksToMoveEditor: 1,
            autoCancel: false
        });
        var store = new Ext.create('MyDesktop.store.Users',{
        	data : me.statics
        });
        if(!win){
            win = desktop.createWindow({
                id: 'user-manage',
                title:'用户管理',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                animCollapse:false,
                constrainHeader:true,
                layout: 'fit',
                items: [{
                    store: store,
                    columns: [{
                        header: '用户名',
                        dataIndex: 'username',
                        flex: 1,
                        editor: {
                            // defaults to textfield if no xtype is supplied
                            allowBlank: false
                        }
                    }, {
                        header: '密码',
                        dataIndex: 'password',
                        width: 160,
                        editor: {
                            allowBlank: false
                        }
                    }, {
                        xtype: 'datecolumn',
                        header: '创建日期',
                        dataIndex: 'createdDate',
                        width: 105,
                        editor: {
                            xtype: 'datefield',
                            allowBlank: false,
                            format: 'm/d/Y',
                            //minValue: '01/01/2006',
                            //minText: 'Cannot have a start date before the company existed!',
                            maxValue: Ext.Date.format(new Date(), 'm/d/Y')
                        }
                    }],
                    renderTo: 'editor-grid',
                    width: 600,
                    height: 400,
                    title: '管理员用户列表',
                    frame: true,
                    tbar: [{
                        text: '添加用户',
                        iconCls: 'employee-add',
                        handler : function() {
                            rowEditing.cancelEdit();

                            // Create a model instance
                            var r = Ext.create('MyDesktop.model.User', {
                                username: '输入用户名',
                                password: '123456',
                                createdDate: Ext.Date.clearTime(new Date()),
                                userCategory:1
                            });

                            store.insert(0, r);
                            rowEditing.startEdit(0, 0);
                        }
                    }, {
                        itemId: 'removeEmployee',
                        text: '删除用户',
                        iconCls: 'employee-remove',
                        handler: function() {
//                            var sm = grid.getSelectionModel();
//                            rowEditing.cancelEdit();
//                            store.remove(sm.getSelection());
//                            if (store.getCount() > 0) {
//                                sm.select(0);
//                            }
                        },
                        disabled: true
                    }],
                    plugins: [rowEditing],
                    listeners: {
                        'selectionchange': function(view, records) {
                            //grid.down('#removeEmployee').setDisabled(!records.length);
                        }
                    }
                }]
                        
            });
        }
        return win;
    },

    statics: [{
    	id:"fdskjflakdfa",username:"lihe911119",password:"911119",createdDate:new Date()
    }]
});

